package cn.net.codeplus.controller;

import java.util.Date;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.net.codeplus.entity.Message;
import cn.net.codeplus.service.IMessageService;

/**
 * 联系我们控制器
 * @author jameszhou
 *
 */
@Controller
@RequestMapping("/contact")
public class ContactController {

	@Autowired private IMessageService messageServer;
	
	/**
	 * 联系我们页面
	 * @param map
	 * @return
	 */
	@RequestMapping("/index")
	public String index(ModelMap map) {
		return "contact";
	}
	
	/**
	 * 联系我们提交数据
	 * @param map
	 * @return
	 */
	@RequestMapping("/submit")
	public String submit(Message message,RedirectAttributes model) {
		message.setId(UUID.randomUUID().toString());
		message.setCreateTime(new Date());
		messageServer.insert(message);
		model.addFlashAttribute("msg","提交成功");
		return "redirect:/contact/index.html";
	}

}
